class Solution {
public:
    int search(vector<int>& nums, int target) {
        int head = 0, tail = nums.size() - 1, mid;
        while (head <= tail) {
            mid = (head + tail) >> 1;
            if (nums[mid] == target) return mid;
            if (nums[mid] < target) head = mid + 1;
            else tail = mid - 1;
        }
        return -1;
    }
};
